package handler

import (
	"github.com/gin-gonic/gin"
	"role-player/models"
	"role-player/pkg"
)

func Login(c *gin.Context) {
	username := c.PostForm("username")
	password := c.PostForm("password")
	data := models.User{
		Username: username,
		Password: password,
	}
	if err := models.DB.Where("username=?", username).First(&data).Error; err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "用户不存在",
		})
	}
	if data.Password != pkg.Md5(password) {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "密码不正确",
		})
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "登录成功",
	})

}
